package com.zmm.weblog.common.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.extern.slf4j.Slf4j;

/**
 * @author 福禄寿
 */
@Slf4j
public class JsonUtil {
    private static final ObjectMapper INSTANCE = new ObjectMapper();

    public static String toJsonString(Object object) {

        try {
            INSTANCE.registerModule(new JavaTimeModule());
            return INSTANCE.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            log.error("json序列化失败", e);
            return object.toString();
        }
    }
}
